//
//  GSNewsImageCell.m
//  GameSky
//
//  Created by lanou on 16/1/10.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSNewsImageCell.h"

#define kMargin 8
#define kImageW (kScreenWidth - 4 * kMargin) / 3

@implementation GSNewsImageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        [self setUp];
        
    }
    return self;
}

- (void)setUp
{
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleLabel];
    
    self.leftImage = [[UIImageView alloc] init];
    self.midImage = [[UIImageView alloc] init];
    self.rightImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.leftImage];
    [self.contentView addSubview:self.midImage];
    [self.contentView addSubview:self.rightImage];
    
    self.commentLabel = [[UILabel alloc] init];
    self.commentLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
    self.commentLabel.textAlignment = NSTextAlignmentRight;
    self.commentLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.commentLabel];
    
    _titleLabel.sd_layout
    .topSpaceToView(self.contentView,kMargin)
    .leftSpaceToView(self.contentView,kMargin)
    .rightSpaceToView(self.contentView,kMargin)
    .autoHeightRatio(0);
    
    _leftImage.sd_layout
    .leftSpaceToView(self.contentView,kMargin)
    .topSpaceToView(_titleLabel,kMargin)
    .widthIs((kScreenWidth - 4 * kMargin)/3)
    .autoHeightRatio(0.6);
    
    _midImage.sd_layout
    .leftSpaceToView(_leftImage,kMargin)
    .topEqualToView(_leftImage)
    .widthIs((kScreenWidth - 4 * kMargin)/3)
    .autoHeightRatio(0.6);
    
    _rightImage.sd_layout
    .leftSpaceToView(_midImage,kMargin)
    .rightSpaceToView(self.contentView,kMargin)
    .widthIs((kScreenWidth - 4 * kMargin)/3)
    .topEqualToView(_midImage)
    .autoHeightRatio(0.6);
    
    _commentLabel.sd_layout
    .topSpaceToView(_rightImage,kMargin)
    .rightSpaceToView(self.contentView,kMargin)
    .heightIs(20);
    
    [self setupAutoHeightWithBottomView:_commentLabel bottomMargin:kMargin];
    
}

- (void)setModel:(GSNewsListModel *)model {
    _model = model;
    
    self.titleLabel.text = model.title;
    
    [self.leftImage sd_setImageWithURL:[NSURL URLWithString:model.thumbnailURLsArray[0]] placeholderImage:kPHImage];
    
    [self.midImage sd_setImageWithURL:[NSURL URLWithString:model.thumbnailURLsArray[1]] placeholderImage:kPHImage];
    
    if (model.thumbnailURLsArray.count == 3) {

        [self.rightImage sd_setImageWithURL:[NSURL URLWithString:model.thumbnailURLsArray[2]] placeholderImage:kPHImage];
    }
    
   
    self.commentLabel.text = [NSString stringWithFormat:@"%@评论",model.commentsCount];
    
}

@end
